# 方法一：不好，两个列表多占内存，min()和remove()影响时间复杂度
def select_sort_simple(li):
    li_new = []
    for i in range(len(li)):
        min_val = min(li)
        li_new.append(min_val)
        li.remove(min_val)
    return li_new


# 方法二：
def select_sort(li):
    for i in range(len(li) - 1):  # i是第几趟
        min_loc = i  # 无序区第一个元素下标
        for j in range(i, len(li)):  # 列表元素循环
            if li[j] < li[min_loc]:  # 对比元素大小
                min_loc = j
        li[i], li[min_loc] = li[min_loc], li[i]  # 把无序区最小元素放到最前面
        print(li)


li = [3, 4, 2, 1, 5, 6, 8, 7, 9]
# print(select_sort_simple(li))
print(select_sort(li))
